﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.events.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Events.*;
    import Classes.*;
    import Display.*;
    import Modules.crew.*;
    import Engine.*;

    public class GMVisit extends GMPlay {

        protected var m_hostId:String;

        public function GMVisit(_arg1:String){
            Global.ui.hideExpandedMainMenu();
            this.m_hostId = _arg1;
            setVisit(this.m_hostId);
            m_uiMode = UIEvent.CURSOR;
        }
        override protected function getSelectableTypes():int{
            return (Constants.WORLDOBJECT_ALL);
        }
        override protected function canBeClicked(_arg1:MouseEvent):Boolean{
            return (((!((m_highlightedObject == null))) && (m_highlightedObject.isVisitorInteractable())));
        }
        override protected function updateCursor():void{
            if (null != m_currentCursor){
                if (m_cursorId > 0){
                    UI.removeCursor(m_cursorId);
                    m_cursorId = 0;
                };
                m_currentCursor = null;
            };
        }
        override protected function handleClick(_arg1:MouseEvent):void{
            var _local2:GameObject;
            var _local3:Boolean;
            if (((((this.canBeClicked(_arg1)) && (m_highlightedObject))) && (m_highlightedObject.isAttached()))){
                _local2 = m_highlightedObject;
                if (_local2.unlimitedVisits){
                    RollCallManager.debugSample("GMVisitHandleClick", "unlimitedVisits");
                    _local3 = true;
                    if (((m_highlightedObject) && ((m_highlightedObject is IMechanicUser)))){
                        _local3 = !(MechanicManager.getInstance().handleAction((m_highlightedObject as IMechanicUser), Global.getClassName(this)));
                    };
                    if ((((_local2 is IMechanicPrePlayAction)) && (!(_local3)))){
                        (_local2 as IMechanicPrePlayAction).onPrePlayTrack();
                    };
                    if (((m_highlightedObject) && (_local3))){
                        m_highlightedObject.onVisitPlayAction();
                    };
                } else {
                    if (this.canInteractWithNeighborObject(_arg1)){
                        if (!_local2.areVisitorInteractionsExhausted){
                            if (Global.player.useVisitorEnergy(1)){
                                this.invokeVisitPlayAction(_local2);
                            } else {
                                m_highlightedObject.displayStatus(ZLoc.t("Main", "NoMoreWork"));
                            };
                        } else {
                            if ((((m_highlightedObject is Business)) || ((m_highlightedObject is Mall)))){
                                m_highlightedObject.displayStatus(ZLoc.t("Main", "AlreadySentTourBus"));
                            };
                        };
                    };
                    if (((_local2) && ((_local2.isAttached() == false)))){
                        dehighlightObject();
                    };
                };
            } else {
                super.handleClick(_arg1);
            };
        }
        private function invokeVisitPlayAction(_arg1:GameObject):void{
            var _local2:IMechanicUser;
            if ((_arg1 is IMechanicUser)){
                _local2 = (_arg1 as IMechanicUser);
                !(MechanicManager.getInstance().handleAction(_local2, Global.getClassName(this)));
            };
            if (_arg1){
                _arg1.onVisitPlayAction();
            };
        }
        protected function canInteractWithNeighborObject(_arg1:MouseEvent):Boolean{
            return (((((m_highlightedObject) && (this.canBeClicked(_arg1)))) && ((m_highlightedObject.isAttached() == true))));
        }

    }
}//package GameMode 
